Skip to content

release geodifflib on shutdown() for macOS - #261

Open
harminius wants to merge 1 commit into
masterfrom
fix/shutdown-for-unix-os
Open

release geodifflib on shutdown() for macOS#261
harminius wants to merge 1 commit into
masterfrom
fix/shutdown-for-unix-os

Conversation

@harminius

Copy link
Copy Markdown

Fixes MerginMaps/qgis-plugin#867 and maybe MerginMaps/qgis-plugin#866

Problem:
shutdown() previously only released the library on Windows; on Linux/macOS it just dropped the Python reference, so ctypes never called dlclose() and the image stayed mapped. On macOS the old and new copies of the library coexisted in the process resulting in QGIS to crash.

Solution:
This makes pygeodiff.shutdown() actually unload the library on macOS.

Limitation:
dlclose() is best-effort - on modern Linux (glibc ≥ 2.34) the library often stays mapped anyway. However, the bug doesn't appear on Linux because it re-dlopen() the lib by its name (SONAME). This means only one copy is ever loaded - unfortunately, the old one.
Also added a small guard so a failed load doesn't raise in __del__.

@harminius
harminius requested a review from wonder-sk August 28, 2026 10:52

@wonder-sk wonder-sk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix looks sensible....

Comment thread pygeodiff/geodifflib.py
Comment on lines +77 to +78
lib = getattr(self, "lib", None)
if lib is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is ugly... better to init self.lib = None in the __init__() instead of this

@wonder-sk wonder-sk closed this Sep 3, 2026
@wonder-sk wonder-sk reopened this Sep 3, 2026
@wonder-sk

Copy link
Copy Markdown
Contributor

@harminius let's rebase on top of master to get CI green for windows build of wheels

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QGIS 3.44 macOS (Apple Silicon): crash on project download right after plugin (re)install (works after restart)

2 participants